package cn.cdeden.resource.service.impl;

import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.common.core.utils.StringUtils;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.common.mybatis.core.page.PageQuery;
import cn.cdeden.common.mybatis.validator.QueryHelpMybatisPlus;
import cn.cdeden.resource.domain.SysOssDownloadRecord;
import cn.cdeden.resource.domain.bo.SysOssDownloadRecordBo;
import cn.cdeden.resource.domain.domain.FilePrintLog;
import cn.cdeden.resource.domain.dto.FilePrintLogDto;
import cn.cdeden.resource.domain.dto.FilePrintLogQueryParam;
import cn.cdeden.resource.domain.vo.SysOssDownloadRecordVo;
import cn.cdeden.resource.mapper.FilePrintLogMapper;
import cn.cdeden.resource.service.FilePrintLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author GW
* @date 2024-05-23
*/
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = FilePrintLogService.CACHE_KEY)
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class FilePrintLogServiceImpl implements FilePrintLogService {

    // private final RedisUtils redisUtils;
    private final FilePrintLogMapper filePrintLogMapper;

    @Override
    public TableDataInfo<FilePrintLogDto> queryAll(FilePrintLogDto query, PageQuery pageQuery) {
        LambdaQueryWrapper<FilePrintLog> lqw = buildQueryWrapper(query);
        IPage<FilePrintLogDto> page = filePrintLogMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public TableDataInfo<FilePrintLogDto> queryAll(FilePrintLogQueryParam filePrintLogQueryParam, Pageable pageable) {
        return null;
    }

    private LambdaQueryWrapper<FilePrintLog> buildQueryWrapper(FilePrintLogDto bo) {
        LambdaQueryWrapper<FilePrintLog> lqw = Wrappers.lambdaQuery(FilePrintLog.class);
        lqw.orderByDesc(FilePrintLog::getCreateTime); // 创建时间降序
        return lqw;
    }

    @Override
    public Integer save(FilePrintLogDto filePrintLog) {
        FilePrintLog convert = MapstructUtils.convert(filePrintLog, FilePrintLog.class);
        int insert = filePrintLogMapper.insert(convert);
        filePrintLog.setId(convert.getId());
        return insert;
    }
}
